module.exports = app => {
	const Sequelize = app.Sequelize;
	const role = app.model.define('roles', {
		id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
		name: {type: Sequelize.STRING(50), allowNull: false, defaultValue: '', comment: '角色名称'},
		is_default: {type: Sequelize.TINYINT, allowNull: false, defaultValue: 0, comment: '是否为默认角色'},
	})
	role.associate = function() {
		app.model.Roles.belongsToMany(app.model.Permissions, {
      through: app.model.RolePermissions,
      foreignKey: 'role_id',
      otherKey: 'permission_id',
    });
		app.model.Roles.belongsToMany(app.model.Menus, {
      through: app.model.RoleMenus,
      foreignKey: 'role_id',
      otherKey: 'menu_id',
    });
	}
	return role;
}